import Vue from 'vue'
import VueRouter from 'vue-router'

// import ShopProductAdd from '../views/shop/product/add/add.vue'
// import Login from '../views/auth/login/login/login.vue'
// import Index from '../views/auth/index/index/index.vue'
// import Main from '../views/auth/index/main/main.vue'
// import AuthAdminIndex from '../views/auth/auth_admin/index/index.vue'
// import AuthGroupIndex from '../views/auth/auth_group/index/index.vue'
// import AuthRuleIndex from '../views/auth/auth_rule/index/index.vue'
// import AuthConfigIndex from '../views/auth/auth_config/index/index.vue'
const Login = () => import(/* webpackChunkName: 'auth_index' */ '../views/auth/login/login/login.vue')
const Index = () => import(/* webpackChunkName: 'auth_index' */ '../views/auth/index/index/index.vue')
const Main = () => import(/* webpackChunkName: 'auth_index' */ '../views/auth/index/main/main.vue')

const AuthAdminIndex = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/auth_admin/index/index.vue')
const AuthGroupIndex = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/auth_group/index/index.vue')
const AuthRuleIndex = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/auth_rule/index/index.vue')
const AuthConfigIndex = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/auth_config/index/index.vue')
const AuthAreaIndex = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/area/index/index.vue')
const AuthAreaIndex1 = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/area/index1/index.vue')
const AuthAreaIndex2 = () => import(/* webpackChunkName: 'auth_admin' */ '../views/auth/area/index2/index.vue')

const ShopProductTypeIndex = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product_type/index/index.vue')
const ShopProductAttrbuteKeyIndex = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product_attrbute_key/index/index.vue')
const ShopProductAttrbuteValueIndex = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product_attrbute_value/index/index.vue')
const ShopProductIndex = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product/index/index.vue')
const ShopProductAdd = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product/add/add.vue')
const ShopProductEdit = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product/edit/edit.vue')
const ShopProductEvaluateList = () => import(/* webpackChunkName: 'shop_product_admin' */ '../views/shop/product/evaluate_list/index.vue')

const ShopUserIndex = () => import(/* webpackChunkName: 'shop_user_admin' */ '../views/shop/user/index/index.vue')
const ShopPictureIndex = () => import(/* webpackChunkName: 'shop_picture_admin' */ '../views/shop/picture/index/index.vue')
const ShopOrderIndex = () => import(/* webpackChunkName: 'shop_order_admin' */ '../views/shop/order/index/index.vue')
const ShopShippedOrderIndex = () => import(/* webpackChunkName: 'shop_order_admin' */ '../views/shop/shipped_order/index/index.vue')
const ShopOrderComplainIndex = () => import(/* webpackChunkName: 'shop_order_admin' */ '../views/shop/order/order_complain/index.vue')
const ShopConsultIndex = () => import(/* webpackChunkName: 'shop_consult_admin' */ '../views/shop/consult/index/index.vue')
const ShopConsultEvaluatendex = () => import(/* webpackChunkName: 'shop_consult_admin' */ '../views/shop/consult/evaluate_index/index.vue')
Vue.use(VueRouter)
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}
const routes = [
  {
    path: '/',
    component: Index,
    redirect: '/main',
    children: [
      { path: '/main', component: Main },
      { path: '/auth/auth_admin/index', component: AuthAdminIndex },
      { path: '/auth/auth_group/index', component: AuthGroupIndex },
      { path: '/auth/auth_rule/index', component: AuthRuleIndex },
      { path: '/auth/auth_config/index', component: AuthConfigIndex },
      { path: '/auth/area/index', component: AuthAreaIndex },
      { path: '/auth/area/index1', component: AuthAreaIndex1 },
      { path: '/auth/area/index2', component: AuthAreaIndex2 },

      { path: '/shop/product_type/index', component: ShopProductTypeIndex },
      { path: '/shop/product_attrbute_key/index', component: ShopProductAttrbuteKeyIndex },
      { path: '/shop/product_attrbute_value/index', component: ShopProductAttrbuteValueIndex },
      { path: '/shop/product/index', component: ShopProductIndex },
      { path: '/shop/product/add', component: ShopProductAdd },
      { path: '/shop/product/edit', component: ShopProductEdit },
      { path: '/shop/product/evaluate_list', component: ShopProductEvaluateList },
      { path: '/shop/user/index', component: ShopUserIndex },
      { path: '/shop/picture/index', component: ShopPictureIndex },
      { path: '/shop/order/index', component: ShopOrderIndex },
      { path: '/shop/shipped_order/index', component: ShopShippedOrderIndex },
      { path: '/shop/order/order_complain', component: ShopOrderComplainIndex },
      { path: '/shop/consult/index', component: ShopConsultIndex },
      { path: '/shop/consult/evaluate_index', component: ShopConsultEvaluatendex }

    ]
  },
  { path: '/login', component: Login }
]
const router = new VueRouter({
  routes
})
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  const token = window.sessionStorage.getItem('token')
  // to 将要访问的路径
  // from 表示从那个路径跳转而来
  // next   next() 表示放行    next('/login')  表示强制跳转
  if (to.path === '/login') {
    if (token) {
      return next('/')
    }
    return next()
  }
  if (!token) {
    return next('/login')
  }
  next()
})

export default router
